<?php
/*========================================= JooSam =========================================/
/																							/
/	Extention:		JooSam																	/
/	Created by:		ScriptPlanet.eu															/
/	Site:			http://www.scriptplanet.eu												/
/	Email:			support@scriptplanet.eu													/
/	Support:		http://www.scriptplanet.eu/support										/
/	Copyright:		2011 (c) ScriptPlanet.eu												/
/	License:		CC BY-NC-ND 3.0 ~ http://creativecommons.org/licenses/by-nc-nd/3.0/		/
/	File Version:	0001																	/
/																							/
/========================================== JooSam ========================================*/
// Joomla Security
defined('_JEXEC') or die;
JHtml::_('behavior.tooltip');
$data = $this->history;

$error = $data[0]['type'];
if($error == 'passed'){
	$c = count($data);
	if($c >= 5){
		$res =	array(
					'type' => 'passed',
					'artist' => JText::_('COM_JOOSAM_ARTIST'),
					'title' => JText::_('COM_JOOSAM_TITLE'),
					'count' => $c,
					'played1' => $data[0]['played'],
					'artist1' => $data[0]['artist'],
					'title1' => $data[0]['title'],
					'played2' => $data[1]['played'],
					'artist2' => $data[1]['artist'],
					'title2' => $data[1]['title'],
					'played3' => $data[2]['played'],
					'artist3' => $data[2]['artist'],
					'title3' => $data[2]['title'],
					'played4' => $data[3]['played'],
					'artist4' => $data[3]['artist'],
					'title4' => $data[3]['title'],
					'played5' => $data[4]['played'],
					'artist5' => $data[4]['artist'],
					'title5' => $data[4]['title']
				);
	}
	else if($c == 4){
		$res =	array(
					'type' => 'passed',
					'artist' => JText::_('COM_JOOSAM_ARTIST'),
					'title' => JText::_('COM_JOOSAM_TITLE'),
					'count' => $c,
					'played1' => $data[0]['played'],
					'artist1' => $data[0]['artist'],
					'title1' => $data[0]['title'],
					'played2' => $data[1]['played'],
					'artist2' => $data[1]['artist'],
					'title2' => $data[1]['title'],
					'played3' => $data[2]['played'],
					'artist3' => $data[2]['artist'],
					'title3' => $data[2]['title'],
					'played4' => $data[3]['played'],
					'artist4' => $data[3]['artist'],
					'title4' => $data[3]['title'],
					'played5' => '',
					'artist5' => '',
					'title5' => ''
				);
	}
	else if($c == 3){
		$res =	array(
					'type' => 'passed',
					'artist' => JText::_('COM_JOOSAM_ARTIST'),
					'title' => JText::_('COM_JOOSAM_TITLE'),
					'count' => $c,
					'played1' => $data[0]['played'],
					'artist1' => $data[0]['artist'],
					'title1' => $data[0]['title'],
					'played2' => $data[1]['played'],
					'artist2' => $data[1]['artist'],
					'title2' => $data[1]['title'],
					'played3' => $data[2]['played'],
					'artist3' => $data[2]['artist'],
					'title3' => $data[2]['title'],
					'played4' => '',
					'artist4' => '',
					'title4' => '',
					'played5' => '',
					'artist5' => '',
					'title5' => ''
				);
	}
	else if($c == 2){
		$res =	array(
					'type' => 'passed',
					'artist' => JText::_('COM_JOOSAM_ARTIST'),
					'title' => JText::_('COM_JOOSAM_TITLE'),
					'count' => $c,
					'played1' => $data[0]['played'],
					'artist1' => $data[0]['artist'],
					'title1' => $data[0]['title'],
					'played2' => $data[1]['played'],
					'artist2' => $data[1]['artist'],
					'title2' => $data[1]['title'],
					'played3' => '',
					'artist3' => '',
					'title3' => '',
					'played4' => '',
					'artist4' => '',
					'title4' => '',
					'played5' => '',
					'artist5' => '',
					'title5' => ''
				);
	}
	else if($c == 1){
		$res =	array(
					'type' => 'passed',
					'artist' => JText::_('COM_JOOSAM_ARTIST'),
					'title' => JText::_('COM_JOOSAM_TITLE'),
					'count' => $c,
					'played1' => $data[0]['played'],
					'artist1' => $data[0]['artist'],
					'title1' => $data[0]['title'],
					'played2' => '',
					'artist2' => '',
					'title2' => '',
					'played3' => '',
					'artist3' => '',
					'title3' => '',
					'played4' => '',
					'artist4' => '',
					'title4' => '',
					'played5' => '',
					'artist5' => '',
					'title5' => ''
				);
	}
	else{
		$res =	array(
					'type' => 'error',
					'artist' => JText::_('COM_JOOSAM_ARTIST'),
					'title' => JText::_('COM_JOOSAM_TITLE'),
					'count' => $c,
					'played1' => $data[0]['played'],
					'artist1' => $data[0]['artist'],
					'title1' => $data[0]['title'],
					'played2' => '',
					'artist2' => '',
					'title2' => '',
					'played3' => '',
					'artist3' => '',
					'title3' => '',
					'played4' => '',
					'artist4' => '',
					'title4' => '',
					'played5' => '',
					'artist5' => '',
					'title5' => ''
				);
	}
}
else{
	$res =	array(
				'type' => 'error',
				'artist' => JText::_('COM_JOOSAM_ARTIST'),
				'title' => JText::_('COM_JOOSAM_TITLE'),
				'count' => '',
				'played1' => $data[0]['played'],
				'artist1' => $data[0]['artist'],
				'title1' => $data[0]['title'],
				'played2' => $c,
				'artist2' => '',
				'title2' => '',
				'played3' => '',
				'artist3' => '',
				'title3' => '',
				'played4' => '',
				'artist4' => '',
				'title4' => '',
				'played5' => '',
				'artist5' => '',
				'title5' => ''
			);
}
echo json_encode($res);
?>